package com.ivsign.lib_idcardidentification;

/**
 * @description :
 * @autHor :  Jason
 * @date : 2018/8/10 10:45
 */

public class BufferUtils {

    public void appendBuffer(byte[] _rawBuffer, byte[] buffer) {
        int _rawBufferSize = _rawBuffer.length;
        if (null == buffer || 0 == buffer.length) return;
        int size = buffer.length + _rawBufferSize;
        if (size <= _rawBuffer.length) {
            System.arraycopy(buffer, 0, _rawBuffer, _rawBufferSize, buffer.length);
            _rawBufferSize += buffer.length;
        } else {
            int newSize = _rawBuffer.length;
            while (newSize <= size) {
                newSize *= 1.5;
            }
            byte[] newRawBuffer = new byte[newSize];
            System.arraycopy(_rawBuffer, 0, newRawBuffer, 0, _rawBufferSize);
            _rawBuffer = newRawBuffer;
            System.arraycopy(buffer, 0, _rawBuffer, _rawBufferSize, buffer.length);
            _rawBufferSize += buffer.length;
        }

    }

    public byte[] getFrontBuffer(byte[] _rawBuffer, int size) {
        if (0 >= size || size > _rawBuffer.length) return null;
        byte[] buffer = new byte[size];
        System.arraycopy(_rawBuffer, 0, buffer, 0, size);
        return buffer;
    }

    public void releaseFrontBuffer(byte[] _rawBuffer, int size) {
        if (0 >= size || size > _rawBuffer.length) return;
        System.arraycopy(_rawBuffer, size, _rawBuffer, 0, _rawBuffer.length - size);
    }


    public static void main(String[] args) {


    }

    private int Check_headTripleFF(int rxcounter, byte[] buff) {
        if ((buff[0] == (byte) 0xff) && (buff[1] == (byte) 0xff) && (buff[2] == (byte) 0xff)) {
            if (rxcounter >= 5) {
                if (rxcounter == ((buff[3] & 0x0F) * 256 + buff[4])) {
                    if ((buff[rxcounter - 2] == (byte) 0xfe) && (buff[rxcounter - 1] == (byte) 0xfe)) {
//                        if (buff[rxcounter - 3] == Verify_Triple_FF(buff)) // 判断校验正确否
//                        {
//                            // memcpy (&TxBuffer[0], &RxBuffer[0],
//                            // RxCounter1_buff);
//                            return 0x9000;
//                        }
                    }
                } else
                    return 0x6ff2;
            }
        }
        return 0x6ff1;
    }
}
